package day11;
/**
 * 单例设计模式
 * @author wangbiao
 *
 */
public class Singleton {
	
	//懒汉式，延迟加载对象实例，同步加双重判断
	//同步解决多线程访问问题，双重判断能减少同步锁判断的次数，提高程序效率
	private static Singleton singleton = null;
	
	private Singleton() {}
	
	public static final Singleton getInstance() {
		if(null == singleton) {
			synchronized(Singleton.class) {
				if(null == singleton) {
					singleton =  new Singleton();
				}
			}
		}
		return singleton;
	}
	/**
	//饿汉式
	private static final Singleton singleton = new Singleton();
	
	private Singleton() {}
	
	public static Singleton getInstance() {
		return singleton;
	}
	*/
}
